package MYJDBC;
import java.sql.*;

public class jdbc {
	 
	    // MySQL 8.0 以上版本 - JDBC 驱动名及数据库 URL
	    static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
	    static final String DB_URL = "jdbc:mysql://localhost:3306/music_web?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC";//这里为自己表所在的数据库名称
	 
	 
	    // 数据库的用户名与密码，需要根据自己的设置
	    static final String USER = "root";
	    static final String PASS = "zwm159123";
	    static final String sqlname = "music_web";
	    
	    public String getSqlUser() {
	    	return USER;
	    }
	    
	    public String getSqlPass() {
	    	
	    	return PASS;
	    }
	    
	    public String getSqlName() {
	    	
	    	return sqlname;
	    }
	    
	    
	    Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
//	    注册数据库||公开
	    public void StatrSql() {
	    	try {
				Class.forName(JDBC_DRIVER);
				try {
					conn = DriverManager.getConnection(DB_URL,USER,PASS);
					stmt = conn.createStatement();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
	    }
	    
//	    执行Query||公开
	    public ResultSet SqlRs(String SqlLanguage) {
	    	
	    	this.StatrSql();
	    	
			try {
				rs = stmt.executeQuery(SqlLanguage);
			} catch (SQLException e) {
				e.printStackTrace();
			}
			return rs;
	    }
	    
//	    执行Update||公开
	    public int SqlUpdate(String SqlLanguage) throws SQLException {
	    	this.StatrSql();
	    	int number = stmt.executeUpdate(SqlLanguage);
	    	return number;
	    }
	    
//	    关闭Query资源||公开
	    public void QueryClose() throws SQLException {
	    	rs.close();
	    	stmt.close();
	    	conn.close();
	    }
//	    关闭Update资源||公开
	    public void UpdateClose() throws SQLException {
	    	stmt.close();
	    	conn.close();
	    }
	    
}
